import java.lang.reflect.Field;

public class demo6 {

    public demo6() throws ClassNotFoundException {
        Class clz = Class.forName("Person");
        try {
            Object person = clz.newInstance();
            Field name = clz.getDeclaredField("name");
            name.setAccessible(true);
            System.out.println("赋值前的name:"+name.get(person));
            name.set(person,"New Person");
            System.out.println("赋值前的name:"+name.get(person));
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }
}
